Compute Items Features

First:

Then choose one operation:

Load Parameters and Items


In [ ]:
import json
from utils import load_items

with open('parameters.json', 'r') as infile:
    params = json.load(infile)

RESIZE_X = params['resize']['x']
RESIZE_Y = params['resize']['y']
ITEM_FOLDER = params['item_folder']

items = load_items(ITEM_FOLDER)

Compute and Save


In [ ]:
import cv2, glob
from utils import imread_rgb

def worker(item):
    folder = ITEM_FOLDER + '/' + item + '/'
    files = glob.glob(folder + '*.png')
    for filename in files:
        image_RGB = imread_rgb(filename)
        if not image_RGB is None:
            image_RGB = cv2.resize(image_RGB,(RESIZE_X,RESIZE_Y))
            ...

In [ ]:
%%time
from multiprocessing import Pool

print('Computing XXX of images resized to %d x %d' % (RESIZE_X,RESIZE_Y))
pool_size = 6
pool = Pool(pool_size)
result = []
for item in items:
    result.append( pool.apply_async(worker, (item,)) )
pool.close()
pool.join()
for r in result:
     r.get()

Top

Statistics


In [ ]:
import glob
from utils import ...

item_view = []
VVV = []
for item in items:
    folder = ITEM_FOLDER + '/' + item + '/'
    files = glob.glob(folder + '*_XXX.YYY')
    for filename in files:
        ...
        item_view.append(filename)
        num_sift.append(len(des))

In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline
plt.hist(VVV,bins=60);

In [ ]:
[(ns, str(iv.split('/')[-1][:-9])) for ns, iv in sorted(zip(VVV,item_view), reverse=True) if ns>2000]

In [ ]:
[(ns, str(iv.split('/')[-1][:-9])) for ns, iv in sorted(zip(VVV,item_view), reverse=True) if ns<50]

Top

Plot File


In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline

In [ ]:
import cv2
from ipywidgets import interact
from utils import imread_rgb

def load_and_plot(item,view):
    try:
        prefix = ITEM_FOLDER + '/' + item + '/' + item + '_' + view
        filename = prefix + '.png'
        image_RGB = imread_rgb(filename)
        if not image_RGB is None:
            ...
    except (IOError, OSError):
        print('File not found')

In [ ]:
views = ['top_01','top-side_01','top-side_02','bottom_01','bottom-side_01','bottom-side_02']
interact(load_and_plot,item=items,view=views);

Plot All Items


In [ ]:
for item in items:
    for view in views:
        print(item + '_' + view)
        load_and_plot(item,view)
        plt.show()

Top

Computing Test


In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline

In [ ]:
import cv2, numpy as np
from ipywidgets import interact
from utils import imread_rgb, imread_gray

def compute_and_plot(item,view):
    prefix = ITEM_FOLDER + '/' + item + '/' + item + '_' + view
    filename = prefix + '.png'
    image_RGB = imread_rgb(filename)
    if not image_RGB is None:
        image_RGB = cv2.resize(image_RGB,(RESIZE_X,RESIZE_Y))
        filename = prefix + '_mask.pgm'
        mask = imread_gray(filename)
        ...

In [ ]:
views = ['top_01','top-side_01','top-side_02','bottom_01','bottom-side_01','bottom-side_02']
interact(compute_and_plot,item=items,view=views);

Compute and Plot All Items


In [ ]:
for item in items:
    for view in views:
        print(item + '_' + view)
        plot(item,view)
        plt.show()

Top